package com.basics.post.service.impl;

import com.basics.post.entity.CyChannelPostUser;
import com.basics.post.mapper.CyChannelPostMapper;
import com.basics.post.mapper.CyChannelPostUserMapper;
import com.basics.post.service.CyChannelPostUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 帖子阅读表 服务实现类
 * </p>
 *
 * @author WangWei
 * @since 2025-03-12
 */
@Slf4j
@Service
public class CyChannelPostUserServiceImpl extends ServiceImpl<CyChannelPostUserMapper, CyChannelPostUser> implements CyChannelPostUserService {

    @Autowired
    private CyChannelPostMapper cyChannelPostMapper;

    @Override
    public void readUnReadPost(Long userId, Long channelId){
        log.error("【已读频道ID】-》{}",channelId);
        List<String> postIdList = cyChannelPostMapper.selectUnReadPostList(userId, channelId);
        if(CollectionUtils.isNotEmpty(postIdList)){
            log.error("【已读频道postIdList】-》{}",postIdList);
            List<CyChannelPostUser> list = new java.util.ArrayList<>();
            postIdList.forEach(v->{
                CyChannelPostUser cyChannelPostUser = new CyChannelPostUser();
                cyChannelPostUser.setUserId(userId);
                cyChannelPostUser.setPostId(Long.parseLong(v));
                list.add(cyChannelPostUser);
            });
            saveBatch(list);
        }
    }
}
